<template>
	<!-- 钱包卡片 -->
	<view class="sh-wallet-box u-flex u-m-b-10 u-p-r-20">
		<view class="u-flex wallet-left">
			<view class="wallet-item u-flex-col u-col-center" @tap="login(1)">
				<text class="wallet-item__detail item-balance b-oneline">{{ data.money || '0' }}</text>
				<text class="wallet-item__title">账户余额</text>
			</view>
			<view class="wallet-item u-flex-col u-col-center" @tap="login(2)">
				<text class="wallet-item__detail item-score b-oneline">{{ data.card_total || '0' }}</text>
				<text class="wallet-item__title">电子水票</text>
			</view>
			<view class="wallet-item u-flex-col u-col-center" @tap="login(3)">
				<text class="wallet-item__detail item-coupon b-oneline">{{ data.coupon_total || '0' }}</text>
				<text class="wallet-item__title">优惠券</text>
			</view>
		</view>
<!-- 		<view class="wallet-item u-flex-col wallet-right u-col-center" @tap="jump('/pages/user/wallet/index')">
			<image class="cut-off--line" :src="$IMG_URL + '/imgs/user/cut_off_line.png'" mode=""></image>
			<image class="wallet-img" :src="$IMG_URL + '/imgs/user/wallet.png'" mode="aspectFill"></image>
			<text class="wallet-item__title">我的钱包</text>
		</view> -->
	</view>
</template>

<script>
/**
 * 钱包样式卡片
 */

export default {
	components: {},
	data() {
		return {};
	},
	props:{
		data: {
		  type: Object,
		  default: () => {}
		},
	},
	computed: {
		
	},
	methods: {
		login(index, it) {
			var that = this;
			if (uni.getStorageSync('token') && uni.getStorageSync('mobile')) {
				this.toLink(index, it)
			} else {
				var code = '';
				uni.login({
					provider: 'weixin',
					success: function(logRes) {
						code = logRes.code;
						uni.setStorageSync('code',code)
					}
				});
				if(!uni.getStorageSync('token')){
					// 获取code
					uni.getUserProfile({
						desc: '作为展示',
						success: res => {
							let param = {
								code: code,
								iv: res.iv,
								encryptedData: res.encryptedData,
								rawData: res.rawData,
								signature: res.signature,
								nickname: res.userInfo.nickName,
								avatar: res.userInfo.avatarUrl,
								share_user_id:uni.getStorageSync('shareId')?uni.getStorageSync('shareId'):''
								
							};
							that.$http.authorization(param).then(res => {
								uni.hideToast();
								if (res.code == 1) {
									uni.removeStorageSync('shareId')
									uni.setStorageSync('group_id', res.data.group_id);
									uni.setStorageSync('token', res.data.token);
									uni.setStorageSync('mobile',res.data.mobile?res.data.mobile:'')
									// that.$refs.popup2.close();
									if(uni.getStorageSync('mobile')){
										this.getUser();
										this.toLink(index, it)
									} else{
										this.$refs.tel.open()
									}
									
								}
							});
						},
						fail: err => {
							console.log('获取失败', err);
						}
					});
				} else{
					this.$refs.tel.open()
				}
				
			}
		},
		toLink(index, it){
			if (index == 1) {
				this.$helper.toast('功能开发中');
			}
			if (index == 2) {
				this.$helper.to('/pageCard/views/cardList/cardListGroup');
			}
			if (index == 3) {
				this.$helper.to('/pages/views/coupon/coupon');
			}
		},
	}
};
</script>

<style lang="scss">
// 钱包卡片
.sh-wallet-box {
	background: #fff;
	height: 180rpx;
	position: relative;
	.wallet-left {
		flex: 4;
	}
	.wallet-right {
		position: relative;
		.cut-off--line {
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			right: (750rpx/5) - 15rpx;
			width: 30rpx;
			height: 136rpx;
		}
	}
	.wallet-item {
		flex: 1;
		.wallet-img {
			width: 46rpx;
			height: 46rpx;
		}
		.wallet-item__detail {
			font-size: 40rpx;
			width: 180rpx;
			text-align: center;
			font-weight: 500;
			color: rgba(168, 112, 13, 1);
		}
		.wallet-item__title {
			font-size: 26rpx;
			font-weight: 400;
			color: rgba(153, 153, 153, 1);
			margin-top: 20rpx;
		}
		.item-balance::after {
			content: '元';
			font-size: 16rpx;
			margin-left: 4rpx;
		}
		.item-score::after {
			content: '张';
			font-size: 14rpx;
			margin-left: 4rpx;
		}
		.item-coupon::after {
			content: '张';
			font-size: 16rpx;
			margin-left: 4rpx;
		}
	}
}
.u-flex {
    display: flex;
    flex-direction: row;
    align-items: center;
}
.u-flex-col {
    display: flex;
    flex-direction: column;
}
.u-col-center {
    align-items: center;
}
</style>
